//
//  howUseVC.m
//  UHealth
//
//  Created by hanyou on 15/3/23.
//  Copyright (c) 2015年 gjtx. All rights reserved.
//

#import "howUseVC.h"

@interface howUseVC ()

@property (nonatomic)NSInteger choice;
@property (nonatomic,strong)UIWebView *webV;


@end

@implementation howUseVC

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:kLocal(@"useBtn")];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:kLocal(@"useBtn")];
}

-(id)initWithChoice:(NSInteger)choice andTitle:(NSString *)title
{
    _choice = choice;
    self = [super init];
    if (self) {
        // Custom initialization
        self.view.backgroundColor = kBacColor;
        //        NavView *nav = [[NavView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, kNavHeight) andTitleStr:title andVC:self];
        //        [self.view addSubview:nav];
        
//        UIView *nav = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, kNavHeight)];
//        nav.backgroundColor = kBlueColor;
//        UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 10, 64, 64)];
//        [backBtn setImage:[UIImage imageNamed:@"arrow_left_top_back"] forState:UIControlStateNormal];
//        [backBtn addTarget:self action:@selector(BtnClick:) forControlEvents:UIControlEventTouchUpInside];
        NavView * nav = [[NavView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, kNavHeight) andTitleStr:title andVC:self];
        
//        UILabel *midLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 27, self.view.frame.size.width -200, 30)];
//        midLabel.font = [UIFont systemFontOfSize:17];
//        midLabel.textColor = [UIColor whiteColor];
//        midLabel.text = title;
//        midLabel.textAlignment = NSTextAlignmentCenter;
//        [nav addSubview:backBtn];
//        [nav addSubview:midLabel];
        [self.view addSubview:nav];
        
        
    }
    return self;
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _webV = [[UIWebView alloc]initWithFrame:CGRectMake(0, kNavHeight , WIDTH, HEIGHT - kNavHeight)];
    [self.view addSubview:_webV];
    
    //    if(!kNetIsOK){
    //        [[iToast makeText:kLocal(@"netNoOk")] show];
    //        return ;
    //    }
    if (_choice == 1) {
        
        NSString *filePath = [[NSBundle mainBundle]pathForResource:@"GuideList" ofType:@"html"];
        //        NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
        //        [_webV loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];//不支持回退
        NSURL *localHTMLPageFileURL = [NSURL fileURLWithPath:filePath];
        [_webV loadRequest:[NSURLRequest requestWithURL:localHTMLPageFileURL]];//支持回退
        
        
    }else{
        //        NSString *postStr = [NSString stringWithFormat:@"%@/happ/xtdaynews.jsp",kBaseUrl];
        //        NSURL *mUrl = [NSURL URLWithString:postStr];
        //        NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:mUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5];
        //        [request setHTTPMethod:@"POST"];
        //        NSMutableString *str = [[NSMutableString alloc]init];
        //        [str appendString:[NSString stringWithFormat:@"userid=%ld&",(long)kNetID]];
        //        [str appendString:@"mobile_type=2"];
        //        NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
        //        [request setHTTPBody:data];
        //        [_webV loadRequest:request];
        NSString *filePath = [[NSBundle mainBundle]pathForResource:@"ClassList" ofType:@"html"];
        NSURL *localHTMLPageFileURL = [NSURL fileURLWithPath:filePath];
        [_webV loadRequest:[NSURLRequest requestWithURL:localHTMLPageFileURL]];
        
    }

}


- (void)BtnClick:(UIButton*)btn
{
    if ([_webV canGoBack]) {
        [_webV goBack];
    }else{
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
